import { FAction, leaveType } from '@/plugins/constants'
import dayjs from 'dayjs'
import { defineStore } from 'pinia'
import { v7 as uuidv7 } from 'uuid'
export const useSessionStore = defineStore<'session', any, any>('session', {
  state: () => ({
    systemAccessTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
    meetingId: '',
    clientId: uuidv7(),
    FAction: FAction.INIT,
    sessionId: '',
    configId: '',
    visitorInformation: {},
    brand: '',
    blackList: null, // 黑名单
    auth: 0,
    robotState: 1, // 1开启 2销毁
    robotEvaluate: 0, // 机器人评价 0未完成 1已完成
    agentEvaluate: 0, // 人工评价 0未完成 1已完成
    websocketUrl: '', // websocket连接地址
    // 排队数
    queueNum: 0,
    hasUnReadMessage: false,
    // 留言类型
    leaveType: leaveType.CANCEL_QUEUE,
    transferMenu: null,
    historyPaging: {
      current: 1,
      pageSize: 10,
      total: 0,
      more: true, // 是否还有更多数据
    },
  }),
  actions: {
    updateHistoryPaging(data: any) {
      this.historyPaging = data
    },
    updateTransferMenu(data: any) {
      this.transferMenu = data
    },
    updateUnReadMessageState(data: any) {
      this.hasUnReadMessage = data
    },
    // 更新留言类型
    updateLeaveType(data: any) {
      this.leaveType = data
    },
    // 更新排队数
    updateQueueNum(data: any) {
      this.queueNum = data
    },
    updateActionState(data: any) {
      this.FAction = data
    },
    updateWebsocketUrl(data: any) {
      this.websocketUrl = data
    },
    updateBlackList(data: any) {
      this.blackList = data
    },
    // 机器人状态
    updateRobotState(data: any) {
      this.robotState = data
    },
    updateRobotEvaluateState(data: any) {
      this.robotEvaluate = data
    },
    updateAgentEvaluateState(data: any) {
      this.agentEvaluate = data
    },
    // 更新认证状态
    updateAuthState(data) {
      this.auth = data
    },
    // 更新会议id
    updateMeetingId(data: any) {
      this.meetingId = data
    },
    // 更新用户会话id
    updateSessionId(data: any) {
      this.sessionId = data
    },
    updateVisitor(data: any) {
      this.visitorInformation[data.key] = data.value
    },
    updateConfigId(data: any) {
      this.configId = data
    },
    updateUserPhone(data: any) {
      this.visitorInformation.phone = data
    },
  },
  getters: {
    visitor: (state) => {
      return state.visitorInformation
    },
  },
  persist: {
    key: 'session', //存储名称
    storage: localStorage, // 存储方式
  },
})
